package com.cangiong.flywayexample;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@SpringBootApplication
@RestController
@RequestMapping(value = "/api")
public class FlywayExampleApplication {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	public static void main(String[] args) {
		SpringApplication.run(FlywayExampleApplication.class, args);
	}

	@GetMapping("/users")
	public Object users() {
		String sql = "select name from employee_view";
		RowMapper<String> rowMapper = (resultSet, i) -> resultSet.getString("name");
		List<String> users = jdbcTemplate.query(sql, rowMapper);
		return users;
	}
}
